<?php

namespace App\Repository\Eloquent;

use Anthony\Structure\Criterias\ByCreateTime;
use App\Models\Admin;
use App\Repository\Contracts\AdminRepository;
use App\Repository\Criterias\NoneCancelMessage;
use App\Repository\Criterias\StateSet;
use App\Repository\Filters\Admin\Name;
use Anthony\Structure\Criterias\FilterRequest;
use Anthony\Structure\Eloquent\AbstractRepository;

class AdminRepositoryEloquent extends AbstractRepository implements AdminRepository
{
    protected $filters = [
        // filter and sort settings
        'name' => Name::class,
    ];

    public function entity()
    {
        return Admin::class;
    }

    public function boot()
    {
        $this->pushCriteria(new FilterRequest($this->filters));
    }

    public function findAdminsByPage()
    {
        return $this
            ->pushCriteria(new ByCreateTime())
            ->paginate();
    }

    public function assignToRoles($id, array $roleIds)
    {
        return $this->find($id)->syncRoles($roleIds);
    }

    public function assignToPermission($id, $permissionId)
    {
        return $this->find($id)->syncPermissions([$permissionId]);
    }
}